package com.itheima.chapter10.singleton;

/*
单例设计模式----懒汉式（延迟加载模式）
 */
public class Demo2 {
    public static void main(String[] args) {
        Single2 s = Single2.getInstance();
        Single2 s1 = Single2.getInstance();
        System.out.println(s==s1);
    }
}


class Single2 {
    private Single2() {
    }

    private static Single2 s;

    public static Single2 getInstance() {
        if (s == null) {
            synchronized (Single2.class) {
                if (s == null) {
                    s = new Single2();
                }
            }
        }
        return s;
    }
}
